package demo2;

import java.util.Stack;

public class Test {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        int[] push = {0,1};
        int[] pop = {0,1};
        int[] num = new int[pop.length];
        int i = 0, j = 0;
        stack.push(push[i]);
        for (i = 1, j = 0; i <= push.length && j < pop.length ;) {
            if (stack.empty()) {
                stack.push(push[i]);
                i++;
            }
            if (stack.peek() == pop[j]) {
                num[j] = stack.pop();
                j++;
            } else {
                if (i >= push.length) {
                    System.out.println("false");
                    return; // retrun false
                }
                stack.push(push[i]);
                i++;
            }

        }

        if (i > push.length) {
            System.out.println("false");
            return; // return false;
        }

        if (!stack.empty()) {
            System.out.println("false");
            return; // return false;
        }

        for (int k = 0; k < num.length; k++) {
            if (num[k] != pop[k]) {
                System.out.println("false");
                return;//return false;
            }
        }
        System.out.println("true");
        return; // return true
    }
}
